package com.java.inventory.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author xcc
 * @date 2022/11/18 16:41
 **/
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);


        //这个设置后没有引号，默认是'xxx',设置后是xxx
        template.setKeySerializer(StringRedisSerializer.UTF_8);

        /* 使用Json序列化，默认是JDK序列化 */
        template.setDefaultSerializer(RedisSerializer.json());

//        // 设置支持事物
//        redisTemplate.setEnableTransactionSupport(true);
//        redisTemplate.afterPropertiesSet();
        return template;
    }
}
